/*
 * gntxmms - An XMMS2 curses client
 *
 * commands.c - functions to send playback control commands to xmms2d
 *
 * Copyright 2005, Alexander Botero-Lowry (XMMS2curses)
 * Copyright 2006, Sadrul Habib Chowdhury (gntxmms)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer 
 *    in this position and unchanged.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <xmmsclient/xmmsclient.h>
#include <xmmsclient/xmmsclient-glib.h>

#include "gntxmms.h"

void xmms2_play()
{
   xmmsc_result_t *result;

   result = xmmsc_playback_start(gnt_xmms_get_connection());
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   return;
}

void xmms2_next()
{
   xmmsc_result_t *result;

   result = xmmsc_playlist_set_next_rel(gnt_xmms_get_connection(), 1);
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   result = xmmsc_playback_tickle(gnt_xmms_get_connection());
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   return;
}

void xmms2_jump(int id)
{
   xmmsc_result_t *result;
 
   result = xmmsc_playlist_set_next(gnt_xmms_get_connection(), id);
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   result = xmmsc_playback_tickle(gnt_xmms_get_connection());
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   return;
}

void xmms2_prev()
{
   xmmsc_result_t *result;

   result = xmmsc_playlist_set_next_rel(gnt_xmms_get_connection(), -1);
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   result = xmmsc_playback_tickle(gnt_xmms_get_connection());
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   return;
}

void xmms2_stop()
{
   xmmsc_result_t *result;

   result = xmmsc_playback_stop(gnt_xmms_get_connection());
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);

   return;
}

void xmms2_pause()
{
   xmmsc_result_t *result;
   result = xmmsc_playback_pause(gnt_xmms_get_connection());
   xmmsc_result_wait(result);
   xmmsc_result_unref(result);
   return;
}

#if 0
void xmms2ScrollUp() {
   xmmsc_result_t *newResult;
   gint lineID;
   drawPlayLine=14;
   isScrolling=1;

   if ( lastEntry != playIncrement ) {
        wmove(playlistWindow, 0, 1);
        lineID = g_array_index (playlist, gint, playIncrement);

        newResult = xmmsc_medialib_get_info(gnt_xmms_get_connection(), lineID);
        xmmsc_result_notifier_set(newResult, handle_mediainfo, (int *) 0);
        xmmsc_result_unref(newResult);
        playIncrement++;                

        wdeleteln(playlistWindow);
        move (1, 0);
        vline(ACS_VLINE, 22);
        move (1, 79);
        vline(ACS_VLINE, 22);
        wrefresh(playlistWindow);
   }
}

void xmms2ScrollDown() {
   xmmsc_result_t *newResult;
   gint lineID;
   drawPlayLine=0;
   isScrolling=2;

   if (playIncrement != 15 ) {
       wmove(playlistWindow, 0, 1);
       lineID = g_array_index (playlist, gint, (playIncrement-16));
 
       newResult = xmmsc_medialib_get_info(gnt_xmms_get_connection(), lineID);
       xmmsc_result_notifier_set(newResult, handle_mediainfo, (int *) 0);
       xmmsc_result_unref(newResult);
       playIncrement--;

       winsertln (playlistWindow);
       move (1, 0);
       vline(ACS_VLINE, 22);
       move (1, 79);
       vline(ACS_VLINE, 22);
       wrefresh(playlistWindow);
   }
}
#endif

